package patrol.mobile.com.mobilepatrol.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.widget.TextView;

import butterknife.BindView;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.LaunchBean;
import patrol.mobile.com.mobilepatrol.utils.Constants;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.SPUtils;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

/**
 * Created by apple on 17/9/27.
 */

public class LaunchActivity extends BaseActivity {

    @BindView(R.id.tv_text)
    TextView tvText;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_launch;
    }

    private void getText() {
        HttpSender sender = new HttpSender(this, "http://60.13.217.2:9092/", Urls.LAUNCH_TEXT);
        sender.requestGet(null, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(final String code, String response) {
                LaunchBean launchBean = GsonUtil.GsonToBean(response, LaunchBean.class);
                tvText.setText(launchBean.getContext());
            }
        });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getText();
    }

    @Override
    public void initData() {
        super.initData();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                if (!SPUtils.get(Constants.current_id, "").equals("")) {
                    startActivity(MainActivity.class);
                    finish();
                    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                } else {
                    Intent it = new Intent();
                    it.setClass(LaunchActivity.this, LoginActivity.class);
                    startActivity(it);
                    finish();
                    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                }

            }
        }, 1000 * 2);


    }

    @Override
    public void setListener() {

    }

}
